@extends('layouts.base')

@section('title', '商户')

@section('admin-style')
	<link rel="stylesheet" href="{{ asset('/assets/plugins/dropify/dist/css/dropify.min.css') }}">
@stop

@section('content')
<div class="container-fluid">
	<!-- ============================================================== -->
	<!-- Bread crumb and right sidebar toggle -->
	<!-- ============================================================== -->
	<div class="row page-titles">
	    <div class="col-md-5 align-self-center">
	        <h3 class="text-themecolor">商户--编辑</h3>
	    </div>
	    <div class="col-md-7 align-self-center">
	        <ol class="breadcrumb">
	            <li class="breadcrumb-item"><a href="javascript:void(0)">首页</a></li>
	            <li class="breadcrumb-item">商户管理</li>
	            <li class="breadcrumb-item active">商户编辑</li>
	        </ol>
	    </div>
	</div>
	<div class="row">
	    <div class="col-lg-12">
	        <div class="card">
            	<div class="card-header bg-success">
                    <h4 class="m-b-0 text-white">编辑</h4>
                </div>
                <div class="card-body"></div>
                <div class="card-body">
                    <form class="needs-validation" method="post" action="{{ route('admin.merchants.update', $merchant->id) }}" novalidate enctype="multipart/form-data">  
                        @csrf
                        @method('PUT')
                        <div class="form-group row">
                            <label class="control-label text-right col-md-2" for="">上级经销商：</label>
                            <div class="col-md-7">
                                <select @if(auth('admin')->user()->type == 3) disabled @endif name="parent_id" class="custom-select" required>
                                    @foreach($brokers as $broker)
                                    <option @if($merchant->parent_id == $broker->id) selected @endif value="{{$broker->id}}">{{ $broker->name }}</option>
                                    @endforeach
                                </select>
                                @if ($errors->has('parent_id'))
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $errors->first('parent_id') }}</strong>
                                    </span>
                                @endif
                                <div class="invalid-feedback">
                                   请填写主板类型
                                </div>
                            </div>
                        </div>  
                    	<div class="form-body">
	                        <div class="form-group row">
	                            <label class="control-label text-right col-md-2" for="">用户名：</label>
	                            <div class="col-md-7">
	                                <input type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" id="" name="name" placeholder="用户名" value="{{ old('name', $merchant->name) }}" required>
                                    @if ($errors->has('name'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('name') }}</strong>
                                        </span>
                                    @endif
	                                <div class="invalid-feedback">
                                       请填写用户名
                                    </div>
	                            </div>
	                        </div>  
	                        <div class="form-group row">
	                            <label class="control-label text-right col-md-2" for="">手机号：</label>
	                            <div class="col-md-7">
	                                <input type="text" class="form-control{{ $errors->has('phone') ? ' is-invalid' : '' }}" name="phone" id="" placeholder="手机号" value="{{ old('phone', $merchant->phone) }}" required>
                                    @if ($errors->has('phone'))
                                        <span class="invalid-feedback" role="alert">
                                            <strong>{{ $errors->first('phone') }}</strong>
                                        </span>
                                    @endif
	                            </div>
	                        </div> 
	                        <div class="form-group row">
	                            <label class="control-label text-right col-md-2" for="">头像：</label>
	                            <div class="col-md-7">
	                                <input name="avatar" type="file" id="upload-avatar" class="dropify" data-allowed-file-extensions="jpg png jpeg gif" data-default-file="{{ asset($merchant->avatar) }}"/>
	                            </div>  
	         				</div>
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">状态：</label>
                                <div class="col-md-7">
                                    <input type="radio" value="1" @if ( old('state', $merchant->state) == 1) checked @endif class="check" name="state" data-radio="iradio_square-green" id="square-radio-1">
                                    <label class="custom-control-label" for="square-radio-1">正常</label>
                                    <input type="radio" value="2" @if ( old('state', $merchant->state) == 2) checked @endif class="check"  name="state" data-radio="iradio_square-green" id="square-radio-2">
                                    <label class="custom-control-label" for="square-radio-2">冻结</label>
                                </div> 
                                <div class="invalid-feedback">
                                   请填写上传头像
                                </div> 
                            </div>
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">商户编码：</label>
                                <div class="col-md-7">
                                    <input class="form-control form-white" autocomplete="off" placeholder="输入商户编码" type="text" name="customerNum" value="{{optional($userscode)->customerNum}}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">店铺编码：</label>
                                <div class="col-md-7">
                                    <input class="form-control form-white" autocomplete="off" placeholder="请输入店铺编码" type="text" name="shopNum" value="{{optional($userscode)->shopNum}}">

                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">公钥：</label>
                                <div class="col-md-7">
                                    <input class="form-control form-white" autocomplete="off" placeholder="请输入公钥" type="text" name="shopAccess" value="{{optional($userscode)->shopAccess}}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="control-label text-right col-md-2" for="">私钥：</label>
                                <div class="col-md-7">
                                    <input class="form-control form-white" autocomplete="off" placeholder="请输入私钥" type="text" name="shopSecret" value="{{optional($userscode)->shopSecret}}">
                                </div>
                            </div>
	                    </div>           		
                      	<div class="form-actions">
                            <div class="row">
                                <div class="col-md-8">
                                    <div class="row">
                                        <div class="offset-sm-3 col-md-9">
                                            <button type="submit" class="btn btn-success"> <i class="fa fa-check"></i> 提交</button>
                                            <a href="{{ route('admin.merchants.index') }}"><button type="button" class="btn btn-danger"><i class=" fas fa-times"></i> 取消</button></a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
	    </div>
	</div>
</div>
@stop

@section('admin-js')

<!--Custom JavaScript -->
<script src="{{ asset('assets/js/validation.js') }}"></script>
<!-- jQuery file upload -->
<script src="{{ asset('assets/plugins/dropify/dist/js/dropify.min.js') }}"></script>

<script>
//For validation with custom styles
(function() {
  'use strict';
  window.addEventListener('load', function() {
    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    var forms = document.getElementsByClassName('needs-validation');
    // Loop over them and prevent submission
    var validation = Array.prototype.filter.call(forms, function(form) {
      form.addEventListener('submit', function(event) {
        if (form.checkValidity() === false) {
          event.preventDefault();
          event.stopPropagation();
        }
        form.classList.add('was-validated');
      }, false);
    });
  }, false);
  // 头像上传
    var uploadAvatar = $('#upload-avatar').dropify({
        messages: {
            default: '',
            replace: '',
            remove: '删除',
            error: '上传失败'
        }
    });
    uploadAvatar.on('dropify.beforeClear', function(event, element) {
        return confirm("确定删除 \"" + element.file.name + "\" ?");
    });

    uploadAvatar.on('dropify.afterClear', function(event, element) {
        layer.msg('删除成功');
    });

})();
</script>
@stop